﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace FrbaCommerce.Calificar_Vendedor
{
    public partial class frm_calificarVendedor : Form
    {
        DataRow dr_publicacion;

        public frm_calificarVendedor(DataRow dr_publicacion)
        {
            InitializeComponent();
            this.dr_publicacion = dr_publicacion;
        }

        private void frm_calificarVendedor_Load(object sender, EventArgs e)
        {
            BaseDeDatos baseDeDatos = BaseDeDatos.Instance;
            SqlCommand sqlCommand = new SqlCommand();
            sqlCommand.CommandText = "LOS_GDDES.SP_TRAER_DATOS_PUBLICACION";
            sqlCommand.CommandType = CommandType.StoredProcedure;
            sqlCommand.Parameters.AddWithValue("@id_publicacion", dr_publicacion.Field<Decimal>("id_publicacion"));
            DataTable dt_publicacion = baseDeDatos.consulta(sqlCommand);

            lbl_vendedor.Text = lbl_vendedor.Text + " " + dt_publicacion.Rows[0].Field<string>("USERNAME");
            lbl_descripProducto.Text = lbl_descripProducto.Text + " " + dt_publicacion.Rows[0].Field<string>("DESCRIPCION");
        }

        private void btn_calificar_Click(object sender, EventArgs e)
        {
            BaseDeDatos baseDeDatos = BaseDeDatos.Instance;
            SqlCommand sqlCommand = new SqlCommand();
            sqlCommand.CommandText = "LOS_GDDES.SP_CALIFICAR";
            sqlCommand.CommandType = CommandType.StoredProcedure;
            sqlCommand.Parameters.AddWithValue("@id_calificacion", dr_publicacion.Field<Decimal>("ID_CALIFICACION"));
            sqlCommand.Parameters.AddWithValue("@calificacion", nud_calificacion.Value);
            sqlCommand.Parameters.AddWithValue("@comentario", txt_comentario.Text);
            sqlCommand.Parameters.AddWithValue("@fecha", Convert.ToDateTime(Properties.Settings.Default.FechaDelSistema));
            baseDeDatos.ejecuta(sqlCommand);

            this.Close();
        }
    }
}
